package com.zxmr.utility.service;

import java.sql.SQLException;
import java.util.List;

import com.zxmr.db.DBManager;
import com.zxmr.domain.account.User;
import com.zxmr.domain.component.UserActionTrace;
import com.zxmr.util.Utils;
import com.zxmr.utility.ComponentInit;

public class UserActionTraceService {

	DBManager db = ComponentInit.getDBManager();
	
	public void addActionTrace(UserActionTrace uat)
	{
		try
		{
			db.getMapper().insert("userAction.add", uat);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
	}
	public void addActionTrace(User user,String action)
	{
		UserActionTrace trace = new UserActionTrace();
		trace.setAction(action);
		trace.setCompany(user.getCompany());
		trace.setTime(Utils.getCurrentTime());
		trace.setUser(user.getName());
		
		this.addActionTrace(trace);
	}
	@SuppressWarnings("unchecked")
	public List<UserActionTrace> queryBySearchBean(UserActionSearchBean searchBean)
	{
		try
		{
			return (List<UserActionTrace>)db.getMapper().queryForList("userAction.searchPagination", searchBean);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	public int queryTotalBySearchBean(UserActionSearchBean searchBean)
	{
		try
		{
			return (Integer)db.getMapper().queryForObject("userAction.findCountPagination", searchBean);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return -1;
	}
}
